/**
 * Created by Mark on 2018/4/8.
 * 侧边导航栏
 */

require("./nav-side.css");
var _mm = require('util/mm.js');
var templateIndex = require("./nav-side.string");

//侧边导航
var  navSide = {
    option : {
        name : "",
        navList : [
            {name : 'user-center', desc : '个人中心', href: './user-center.html'},
            {name : 'seller-center', desc : '我的商城', href: './seller-product-list.html'},
            {name : 'order-list', desc : '我的订单', href: './order-list.html'},
            {name : 'user-pass-update', desc : '修改密码', href: './user-password-update.html'},
            {name : 'user-img-center', desc : '更换头像', href: './user-img-center.html'},
            {name : 'user-info-update', desc : '更新信息', href: './user-center-update.html'},
            {name : 'about', desc : '关于网站', href: '#'}
        ]
    },
    //初始化
    init : function (option) {
        //合并选项
        $.extend(this.option,option)
        this.renderNav();
    },
    // 渲染导航菜单
    renderNav : function(){
        // 计算active的选项
        for(var i = 0,iLength = this.option.navList.length ; i < iLength ; i++){
            if(this.option.navList[i].name === this.option.name){
                this.option.navList[i].isActive = true;
            }
        }
        //渲染导航栏子选项
        var  navHtml = _mm.renderHtml(templateIndex,{
            navList : this.option.navList
        });
        //把navHTML追加到容器中
        $(".nav-side").html(navHtml);
    }

};

module.exports = navSide;
